home *** CD-ROM | disk | FTP | other *** search
- /**************************************************************************
- *
- * @@@BUILDINFO@@@ 34variablesPane.jsx 1.0.0.49 07-Feb-2005
- * Copyright 2005 Adobe Systems Incorporated
- * All Rights Reserved.
- *
- * NOTICE: All information contained herein is, and remains the property of
- * Adobe Systems Incorporated and its suppliers, if any. The intellectual
- * and technical concepts contained herein are proprietary to Adobe Systems
- * Incorporated and its suppliers and may be covered by U.S. and Foreign
- * Patents,patents in process,and are protected by trade secret or copyright
- * law. Dissemination of this information or reproduction of this material
- * is strictly forbidden unless prior written permission is obtained from
- * Adobe Systems Incorporated.
- **************************************************************************/
-
- // Code to add to the Local Variables pane
- // The output field of the variables pane is a tree view, but since ScriptUI
- // does not support tree views yet, the interface is at the pane itself.
-
- // Setup the pane. If config.jsx defined configuration data, then convert
- // property names to the form used as path names: a.b => $.global["a]["b"]
- // The property "default" may contain either "include" or "exclude".
-
- // used properties:
- // target - the current target
- // engine - the current engine
- // scope - the JS scope
-
- window.variables.setup = function()
- {
- function convertPath (prop)
- {
- if (prop == "default")
- return prop;
-
- // convert a.b.c to $.global["a"]["b"]["c"]
- var parts = prop.split ('.');
- var path = '$.global';
- for (var i = 0; i < parts.length; i++)
- path += '["' + parts [i] + '"]';
- return path;
- }
-
- if (!this.config)
- this.config = {};
-
- var configAll = this.config ["all"];
- for (var target in this.config)
- {
- if (target == "all")
- continue;
-
- var targetObj = this.config [target];
- var newTargetObj = {};
- // merge in the "all" object if present
- if (configAll)
- {
- for (var prop in configAll)
- newTargetObj [convertPath (prop)] = configAll [prop];
- }
- // make sure that we have a default
- if (!newTargetObj ["default"])
- newTargetObj ["default"] = "include";
-
- // now merge in all the others that we found
- for (var prop in targetObj)
- {
- // this property contains whether to include or to exclude data by default
- var value = (targetObj [prop] == "exclude") ? "exclude" : "include";
- newTargetObj [convertPath (prop)] = value;
- }
- this.config [target] = newTargetObj;
- }
- }
-
- // Get all variables for a specific stack scope.
-
- window.variables.getVariables = function (target, engine, scope, all)
- {
- this.target = target;
- this.engine = engine;
- if (scope.length)
- this.scope = scope;
- else if (this.scope == undefined)
- this.scope = "$.global";
- // pass functions in - we ask for a workspace
- var bt = this._createMessage (prefs.showFunctions);
- if (all)
- {
- bt.headers.All = "1";
- this.clear();
- }
- bt.safeSend();
- }
-
- // Refresh the entire display.
-
- window.variables.refresh = function()
- {
- this.clear();
- // pass functions in - we ask for a workspace
- var bt = this._createMessage (prefs.showFunctions);
- bt.safeSend();
- }
-
- // The callback if the user typed in a new value.
-
- window.variables.onChanged = function (path, value)
- {
- var ok = Document.checkSyntax (value);
- if (ok != true)
- {
- app.beep();
- window.statusLine = ok;
- }
- else
- // eval the expression, but do not print the reply
- currentDebugger.eval (path + '=' + value, true);
- }
-
- // The callback for the Expand event.
-
- window.variables.onExpand = function (path, readOnly, name, value)
- {
- var bt = this._createMessage (prefs.showMethods);
- bt.body = path;
- bt.varName = name;
- bt.varValue = value;
- bt.onOwnError = function (bt)
- {
- window.variables.setInvalid (this.body, this.varName, this.varValue);
- }
- bt.safeSend();
- }
-
- // Helper method. Create and initialize a BridgeTalk message.
-
- window.variables._createMessage = function (doFunctions)
- {
- var bt = BridgeTalk.create (this.target, "Variables");
- bt.headers.Engine = this.engine;
- // create the setting for things to exclude
- bt.headers.Exclude = "xxx";
- if (!prefs.showPredefined)
- bt.headers.Exclude += ",builtin";
- if (!doFunctions)
- bt.headers.Exclude += ",Function";
-
- bt.onOwnResult = function (bt)
- {
- window.variables._readReply (bt, this.body);
- }
- bt.body = this.scope;
-
- return bt;
- }
-
- // Helper method: Interpret the incoming BridgeTalk message body and update the variables.
-
- window.variables._readReply = function (bt, basePath)
- {
- this.clear (basePath);
- // get the exclusion object
- var target = bt.sender.split ('-') [0];
- var config = window.variables.config [target];
- if (!config)
- config = { "default":"include" };
-
- // Update the display. The BridgeTalk instance contains the data. Each body line has 4 elements,
- // the data type, the variable name, the variable value, and a read-only indicator.
-
- var i, reply = bt.splitBody();
- // update all existing items, create a new one if needed
- for (i = 0; i < reply.length; i++)
- {
- // The line has four elements.
- var dataType = reply [i][0];
- var name = reply [i][1];
- var value = reply [i][2];
- var readonly = reply [i][3];
- var isObject = false;
-
- var path;
- if (basePath == "") // local workspace: syntax of names should be OK
- path = name;
- else // other: better use bracket notation
- path = basePath + '["' + app.escape (name) + '"]';
-
- // If the line is an invalid object, the data type is "invalid classname"
- var valid = dataType.substr (0, 8) != "invalid ";
- if (!valid)
- dataType = dataType.substr (8);
-
- switch (dataType)
- {
- case "deleted": this.remove (path);
- path = undefined; break;
- case "undefined": value = undefined; break;
- case "null": value = null; break;
- case "boolean": value = (value == "true"); break;
- case "number": value = parseFloat (eval (value)); break;
- case "string": if (typeof value == "undefined")
- value = ""; break;
- case "Function": // a function may be defined in several ways:
- // Function,foo,foo() defined as function foo(){}
- // Function,foo,() defined as foo = function()
- // Function,bar,foo() defined as bar = foo
- value = "function " + value;
- isObject = true;
- break;
- case "EnumError": // On an enumeration error, strip the EnumError: prefix
- // and create an Error object (the update()
- // method knows how to deal with it)
- var index = value.indexOf (': ');
- if (index > 0)
- value = value.substr (index + 2);
- value = new Error (value);
- break;
- default: isObject = valid;
- // show the class if the value does not start with '['
- if (typeof value == "undefined")
- value = '[' + dataType + ']';
- else if (value.length && value[0] != '[')
- value = '[' + dataType + '] ' + value;
- }
- if (path)
- {
- var include = config [path];
- if (!include)
- include = config ["default"];
- if (include == "include")
- {
- if (valid)
- this.update (path, name, value, isObject, (readonly == "true"));
- else
- this.setInvalid (path, name, "[object " + dataType + "]");
- // recursive call for open objects
- if (isObject && this.isOpen (path))
- {
- // pass methods in - we ask for an object
- var nextBT = this._createMessage (prefs.showMethods);
- nextBT.body = path;
- nextBT.safeSend();
- }
- }
- }
- }
- }
-
- // set up the pane
-
- window.variables.setup();
-